<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        const p1 = new Promise((resolve, reject) => {
            try {
                console.log('请求A数据。。。');
                setTimeout(() => {
                    console.log('请求A数据结束。。。');
                    resolve("A数据")
                }, 1500)

            } catch (e) {
                reject(e.message)
            }
        })
        const p2 = new Promise((resolve, reject) => {
            try {
                console.log('请求b数据。。。');
                setTimeout(() => {
                    console.log('请求b数据结束。。。');
                    resolve("B数据")
                }, 2500)

            } catch (e) {
                reject(e.message)
            }
        })
        const p3 = new Promise((resolve, reject) => {
            try {
                throw new Error('检查网络')
                console.log('请求c数据。。。');
                setTimeout(() => {
                    console.log('请求c数据结束。。。');
                    resolve("B数据")
                }, 2000)

            } catch (e) {
                reject(e.message)
            }
        })

        //使用Promise.all()方法 接受一个数组
        //   const result =Promise.all([p1,p2,p3]);
        //   console.log('result',result);// all方法默认返回状态为pending的promise实例
        //   result.then(value=>{
        //     console.log('全部完成');
        //   }).catch(reason=>{
        //     console.log('有错误',reason);
        //   })

        // 
        const result = Promise.all([p1, p2, p3]);
        console.log("result", result);
        result.then(value => {
            console.log("全部完成");
        }).catch(reason => {
            console.log("有错误的", reason);
        })
    </script>
</body>

</html>